package io.persimmon.core.module.id.instance;

import io.persimmon.core.module.id.IdFactory;
import io.persimmon.core.module.id.bo.BatchId;
import io.persimmon.core.module.id.bo.ListBatchId;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class UUIDFactory implements IdFactory<String> {
    @Override
    public String createId() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    @Override
    public BatchId<String> batchCreateId(int size) {
        return new ListBatchId<String>(size) {
            @Override
            public List<String> batchCreateId(int batchSize) {
                List<String> list = new ArrayList<>(batchSize);
                for (int i = 0; i < batchSize; i++) {
                    list.add(createId());
                }
                return list;
            }
        };
    }
}
